package com.ts.main.mini.controller;

import com.ts.main.mini.dto.AddressDto;
import com.ts.main.mini.dto.AddressPageSearchDto;
import com.ts.main.mini.exception.R;
import com.ts.main.mini.exception.RPage;
import com.ts.main.mini.service.UserAddressServiceImpl;
import com.ts.main.mini.vo.UserAddressVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序-用户地址管理
 * @Author:lk
 * @Date: 2025/5/17  16:08
 */
@AllArgsConstructor
@RestController
@RequestMapping("/mini/user")
@Tag(name = "小程序-用户地址管理")
public class UserAddressController {

    private final UserAddressServiceImpl userAddressService;

    /**
     * 查询用户地址列表（分页查询）
     * @return
     */
    @Operation(summary = "查询用户地址列表（分页查询）")
    @PostMapping("/getAddressPage")
    public RPage<List<UserAddressVo>> getAddressPage(@RequestBody AddressPageSearchDto dto){
        return userAddressService.getAddressPage(dto);
    }

    /**
     * 查询用户地址列表
     * @return
     */
    @Operation(summary = "查询用户地址列表")
    @GetMapping("/getAddressList")
    public R<List<UserAddressVo>> getAddressList(){
        return R.ok(userAddressService.getAddressList());
    }

    /**
     * 查询用户地址详情
     * @return
     */
    @Operation(summary = "查询用户地址详情")
    @GetMapping("/getAddressDetails")
    public R<UserAddressVo> getAddressDetails(@Schema(description = "地址ID") @RequestParam("addressId") Integer addressId){
        return R.ok(userAddressService.getAddressDetails(addressId));
    }

    /**
     * 新增用户地址
     * @return
     */
    @Operation(summary = "新增用户地址")
    @PostMapping("/saveAddress")
    public R<Boolean> saveAddress(@RequestBody AddressDto dto){
        return R.ok(userAddressService.saveAddress(dto));
    }

    /**
     * 修改用户地址
     * @return
     */
    @Operation(summary = "修改用户地址")
    @PutMapping("/updateAddress")
    public R<Boolean> updateAddress(@RequestBody AddressDto dto){
        return R.ok(userAddressService.updateAddress(dto));
    }

    /**
     * 删除用户地址
     * @return
     */
    @Operation(summary = "删除用户地址")
    @DeleteMapping("/deleteAddress")
    public R<Boolean> deleteAddress(@Schema(description = "地址ID集合") @RequestParam("ids") List<Integer> ids){
        return R.ok(userAddressService.deleteAddress(ids));
    }

}
